package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.UserDto;
import com.qk.entity.User;
import com.qk.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/users")
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 用户列表查询
     */
    @GetMapping
    public Result list(UserDto userDto) {
        log.info("用户列表查询: {}", userDto);
        PageResult<User> pageResult = userService.list(userDto);
        return Result.success(pageResult);
    }

    @PutMapping
    public Result add(@RequestBody User user) {
        log.info("新增用户: {}", user);
        userService.add(user);
        return Result.success();
    }
}
